import java.util.Stack;

class MyQueue {

    private Stack<Integer> st1;
    private Stack<Integer> st2;

    public MyQueue() {
        st1 = new Stack<>();
        st2 = new Stack<>();
    }
    
    public void push(int x) {
        if(st1.isEmpty()) {
            st1.push(x);
        }else if(st2.isEmpty()) {
            st2.push(x);
        }else {
            st1.push(x);
        }
    }
    
    public int pop() {
        if(!st1.isEmpty()){
            while(!st1.isEmpty()) {
                st2.push(st1.pop());
            }
            return st2.pop();
        }else {
            while(!st2.empty()) {
                st1.push(st2.pop());
            }
            return st1.pop();
        }
    }
    
    public int peek() {
        if(!st1.isEmpty()){
            while(!st1.isEmpty()) {
                st2.push(st1.pop());
            }
            return st2.peek();
        }else {
            while(!st2.empty()) {
                st1.push(st2.pop());
            }
            return st1.peek();
        }
    }
    
    public boolean empty() {
        return st1.isEmpty()&&st2.isEmpty();
    }
}